/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sdc.event;


import java.util.List;
import sdc.component.type.ComponentTypePool;
import sdc.net.server.appli.ApplicationServer;
import sdc.net.server.appli.ApplicationServerManager;
/**
 *
 * @author masa
 */
public class ScenarioEvent extends Event{

    private int scenarioNum;

    public ScenarioEvent(double eventTime ,int scenarioNum){
        super(eventTime);
        this.scenarioNum = scenarioNum;
    }

    @Override
    public void fire(){
        switch(scenarioNum){
            case(1):
                scenario1();
                break;
            case(2):
                scenario2();
                break;
            case(3):
                scenario3();
                break;
            case(4):
                scenario4();
                break;
        }
    }

    private void scenario1(){
        double[][] probMatrix = {
            {-1.0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 1.0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
            {   0,   0,-1.0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 1.0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,-1.0,   0,   0, 1.0,   0,   0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0, 1.0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,   0,   0,-1.0,   0,   0,   0,   0,   0,   0,   0, 1.0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 1.0},
            {   0,   0,   0,   0,   0,   0,   0,   0,-1.0,   0,   0,   0,   0, 1.0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0, 1.0,   0,   0,   0,   0,   0},
            {   0,   0,   0,   0,   0,   0,   0,   0,   0, 1.0,   0,   0,   0,   0,   0},
        };
        ComponentTypePool.INSTANCE.setMatrix(probMatrix);
        List<ApplicationServer> appList = ApplicationServerManager.INSTANCE.getShuffledList();
        for(ApplicationServer app : appList.subList(0, appList.size())){
            app.clearUseComponentMap();
            app.createService(3);
        }
    }

    private void scenario2(){
        List<ApplicationServer> appList = ApplicationServerManager.INSTANCE.getShuffledList();
        for(ApplicationServer app : appList.subList(0, appList.size())){
            app.setMu(20.0);
        }
    }

    private void scenario3(){
        List<ApplicationServer> appList = ApplicationServerManager.INSTANCE.getShuffledList();
        for(ApplicationServer app : appList.subList(0, appList.size() / 2)){
            app.setMu(1.5);
        }
        for(ApplicationServer app : appList.subList(appList.size() / 2 + 1, appList.size())){
            app.setMu(0.5);
        }
    }

    private void scenario4(){
        List<ApplicationServer> appList = ApplicationServerManager.INSTANCE.getShuffledList();
        for(ApplicationServer app : appList.subList(0, appList.size() / 3)){
            app.setMu(1.0);
        }
        for(ApplicationServer app : appList.subList(appList.size() / 3 + 1, appList.size() / 3 * 2)){
            app.setMu(0.0);
        }
        for(ApplicationServer app : appList.subList(appList.size() / 3 * 2 + 1, appList.size())){
            app.setMu(2.0);
        }
    }
}
